package com.meilai.project.controller.web.adMake.mapper;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meilai.project.controller.web.adMake.dto.BillAdMakeGenConfirmCountDTO;
import com.meilai.project.controller.web.adMake.dto.BillAdMakeMediaCountDTO;
import com.meilai.project.controller.web.adMake.dto.BillAdMakePointDTO;
import com.meilai.project.controller.web.adMake.dto.BillAdMakeSearchParams;
import com.meilai.project.controller.web.adMake.entity.BillAdMake;
import com.meilai.project.controller.web.adMake.vo.BillAdMakePicCountVO;
import com.meilai.project.controller.web.adMake.vo.BillAdMakePointFromMarketVO;
import com.meilai.project.controller.web.adMake.vo.BillAdMakeWebVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author yxg
 * @Date 2022/8/3 0:37
 */
@Mapper
public interface BillAdMakeMapper extends BaseMapper<BillAdMake> {
    @Update("update bill_ad_make set contract_id = #{newContractId} where contract_id = #{oldContractId}")
    void updateContractId(@Param("oldContractId") Long oldContractId, @Param("newContractId") Long newContractId);

    /**
     * 查询供应商清单信息
     */
    List<BillAdMakePicCountVO> getSupplierPicCount(@Param("ad_make_ids") List<Long> ad_make_ids);

    /**
     * 查询制作单对应的资源类型和数量
     * @param ad_make_ids 制作单ids
     */
    List<BillAdMakeMediaCountDTO> getMediaTypeCount(@Param("ad_make_ids") List<Long> ad_make_ids);

    List<BillAdMakeGenConfirmCountDTO> getGenConfirmCount(@Param("ad_make_ids") List<Long> ad_make_ids);

    /**
     * @author 张驰
     * @description 格局市场单id，查询VO
     * @date 2022-08-16 16:18
     * @param market_id 市场单id
     */
    BillAdMakePointFromMarketVO getVOByMarketId(@Param("market_id") Long market_id);
    /**
     * @author 张驰
     * @description 格局市场单id，查询点位数据
     * @date 2022-08-16 12:15
     * @param market_id 市场单id
     */
    List<BillAdMakePointDTO> getPointsByMarketId(@Param("market_id") Long market_id);

    @Select("select DISTINCT size_width_inside as size_width, size_height_inside as size_height, concat(size_width_inside, '*', size_height_inside) as name from media_point " +
            "where status=1 and size_width_inside is not null and size_height_inside is not null and media_type_id=#{media_type_id}")
    List<JSONObject> listMediaTypeSpec(@Param("media_type_id") Long media_type_id);

    @Select("select DISTINCT d.id, d.name from media_point mp join dictionary d on d.id=mp.pic_type_id " +
            "where mp.status=1 and mp.media_type_id=#{media_type_id} and mp.size_width_inside=#{size_width} and mp.size_height_inside=#{size_height}")
    List<JSONObject> listMediaPicType(@Param("media_type_id") Long media_type_id, @Param("size_width") String size_width, @Param("size_height") String size_height);

    List<BillAdMakeWebVO> selectPageList(Page<BillAdMakeWebVO> page, @Param("query") BillAdMakeSearchParams params);

    List<BillAdMakeWebVO> selectPageList(@Param("query") BillAdMakeSearchParams params);

    BillAdMakeWebVO queryDetailById(@Param("id") Long id);

}
